package br.com.fatecjp.pooai.gerenciador.taxi.ambiente;

public class Posicao {

	private int x;
	private int y;

	public Posicao(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return this.x;
	}

	public int getY() {
		return this.y;
	}

	public Posicao obterProximaPosicao(Posicao destino) {

		int xProxima;
		if (x > destino.x) {
			xProxima = x - 1;
		} else if (x < destino.x) {
			xProxima = x + 1;
		} else {
			xProxima = x;
		}

		int yProxima;
		if (y > destino.y) {
			yProxima = y - 1;
		} else if (y < destino.y) {
			yProxima = y + 1;
		} else {
			yProxima = y;
		}

		return new Posicao(xProxima, yProxima);

	}

	public double obterDistancia(Posicao outraPosicao) {
		return Math.sqrt(Math.pow(outraPosicao.x - x, 2)
				+ Math.pow(outraPosicao.y - y, 2));
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Posicao other = (Posicao) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

}
